<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="css/bootstrap.min.css">

    <!-- Loding font -->
    <link href="https://fonts.googleapis.com/css?family=Montserrat:300,700" rel="stylesheet">

    <!-- Custom Styles -->
    <link rel="stylesheet" type="text/css" href="css/styles.css">

    <title>登录页面</title>
</head>
<body>

<!-- Backgrounds -->

<div id="login-bg" class="container-fluid">

    <div class="bg-img"></div>
    <div class="bg-color"></div>
</div>

<!-- End Backgrounds -->

<div class="container" id="login">
    <div class="row justify-content-center">
        <div class="col-lg-8">
            <div class="login">

                <h1>登录</h1>

                <!-- Loging form -->
                <form action="/user/userLogin" method="post">
                    <div class="form-group">
                        <!-- <input type="text" name="username" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="请输入账号"> -->
                        <span class="add-on bg_lg"><i class="icon-user"></i></span><input type="text" id="usernameId" name="username" class="form-control" placeholder="请输入人账号" />

                    </div>
                    <div class="form-group">
                        <!-- <input type="password" name="password" class="form-control" id="exampleInputPassword1" placeholder="请输入密码"> -->
                        <span class="add-on bg_ly"><i class="icon-lock"></i></span><input type="password" id="passwordId" name="password" class="form-control" placeholder="请输入密码" />
                    </div>

                    <div class="form-check">



                    </div>

                    <br>
                    <!-- <button type="submit" class="btn btn-lg btn-block btn-success">登录</button> -->
                    <!--                    <input type="submit" value="登录" class="btn btn-lg btn-block btn-success"/> -->
                    <button type="button" class="btn btn-primary btn-block btn-flat btn-login" >登录</button>
                </form>
                <!-- End Loging form -->

            </div>
        </div>
    </div>
</div>

<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>

<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>

<script src="plugins/iCheck/icheck.min.js"></script>


<script>
    $(function () {
        $(".btn").click(doLogin);
    });
    function doLogin(){
        let username=$("#usernameId").val();
        let password=$("#passwordId").val();
        let url=`http://localhost:80/user/login/${username}/${password}`;
        $.ajax({
            url:url,
            crossDomain:true,
            xhrFields:{withCredentials:true},
            success(result){
                if(result.state==1){
                    //跳转到indexUI对应的页面
                    //原生写法(创建cookie)
                    document.cookie=`username=${result.data}; path=/`;
                    //借助jquery中的cookie插件
                    //$.cookie('username',result.data);
                    location.href="/CGB_index.html";
                }else{
                    $(".login-box-msg").html(result.message);
                }
                return false;//防止刷新时重复提交
            }});
    }

</script>
</body>
</html>